package com.netscenery.yang.model;

import com.netscenery.util.Field;

public class Unique extends Field {
	private YangList list;
	
	public Unique(YangList list,String fields){
		super(fields);
		this.list = list;
	}

	/**
	 * @return the list
	 */
	public YangList getList() {
		return list;
	}

	/**
	 * @param list the list to set
	 */
	public void setList(YangList list) {
		this.list = list;
	}
	
	public Node getUniqueNode(String unique){
		if (null == unique){
			return null;
		}
		
		if (!hasField(unique)){
			return null;
		}
		
		if (null == list){
			return null;
		}
		return ModelElement.getNodeByDescendantPath(list.getEnv(), list, unique);
	}
	
	public Node getUniqueNode(int index){
		String unique = getField(index);
		if (null == unique){
			return null;
		}		
		if (null == list){
			return null;
		}
		return ModelElement.getNodeByDescendantPath(list.getEnv(), list, unique);
	}
}
